package com.xzx.spark.core.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 *
 * ${DESCRIPTION}
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2021-06-26 8:39 下午
 */
object Spark005_Glom {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("Spark005_Glom")
    val context = new SparkContext(conf)
    val rdd: RDD[Int] = context.makeRDD(List(1, 2, 3, 4), 2)
    val glomRDD: RDD[Array[Int]] = rdd.glom()
    glomRDD.collect().foreach(x => println(x.mkString(",")))

    //计算所有分区最大值求和（分区内取最大值，分区间最大值求和）
    println(rdd.glom().map(x => x.max).collect().sum)
    context.stop()
  }
}
